﻿
@{
    ViewBag.Title = "AddUser";
}
<style>
    footer{
        position:fixed;
        left:0;
        bottom:0;
        z-index:100;
        width:100%;
    }
    .panel{
        width:50%;
    }
    .panel-title{
        text-align:center;
    }
    #alert-mes{
        text-align:center;
        width:50%;
        background-color:white;
        color:black;
    }
    #sel{
        display:none;
    }
    .sel-office{
        display:none;
    }
    .panel-footer{
        text-align:right;
    }
    .panel-default > .panel-heading {
        color: #fff;
        background-color: #93969A;
        border-color: #93969A;
    }
    .panel-default {
        border-color: #000;
    }     .btn-submit {
        color: #fff;
        background-color: #93969A;
        border-color: #93969A;
    }

    .btn-return {
        color: #fff;
        background-color: #93969A;
        border-color: #93969A;
    }
</style>
<div id="alert-mes">
    @Html.ValidationMessage("AddUserError")
    <button class="close" data-dismiss="alert">&times;</button>
</div>
<br />
<div class="panel panel-default">
    <div class="panel-heading">
        <div class="panel-title">添加用户</div>
    </div>
  <form action="/BaseInfos/AddUserInfos" method="post" class="form-horizontal">
    <div class="panel-body">
            <label class="control-label col-xs-2">登录名：</label>
            <div class="input-group col-xs-6">
                <input class="form-control" id="UN" name="UserName" />
            </div>
            <br />
            <label class="control-label col-xs-2">密码:</label>
            <div class="input-group col-xs-6">
                <input name="userpwd" class="form-control" />
            </div>
            <br />
            <label class="control-label col-xs-2">职位:</label>
            <div class="input-group col-xs-6">
                <select id="sel-job" name="role_id" class="form-control">
                    <option>请选择</option>
                    @{
                        foreach (var item in ViewBag.rolelist)
                        {
                            <option value="@item.id">@item.RoleName</option>
                        }
                    }
                </select>
            </div>
            <br />
            <div class="sel-office">
                <label class="control-label col-xs-2">单位类型:</label>
                <div class="input-group col-xs-6">
                    <button type="button" class="btn btn-default" value="1" onclick="selinfos(this);">司法鉴定机构</button>
                    &nbsp;&nbsp;<button type="button" class="btn btn-default" style="width:110px" value="2" onclick="selinfos(this);">保险公司</button>
                </div>
            </div>
            <label class="control-label col-xs-2"></label>
            <div  class="input-group col-xs-6">
                <select id="sel" name="" class="form-control"></select>
            </div>              
    </div>
    <div class="panel-footer">
        <button type="submit" class="btn btn-submit">提交</button>
        <a href="/BaseInfos/UserInfosIndex" class="btn btn-return">返回</a>
    </div>
 </form>
</div>
<script type="text/javascript">
    $(function () {
        if ($('#alert-mes').find('span').html() != "") {
            $('#alert-mes').attr('class', 'alert alert-danger');
            $('.close').css('display', 'block');
        } else {
            $('.close').css('display', 'none');
        }
    })
    function selinfos(btn) {
        $('#sel').html("");
        $('#sel').css('display', 'block');
        var a = $(btn).val();
        if (a == 1) {
            $.post('/BaseInfos/selectorganization', { 'num': a }, function (o) {
                console.log(o);
                $('#sel').attr('name', 'unit_id');
                for (var i = 0; i < o.length; i++) {
                    var hm = $('<option value='+o[i].id+'>'+o[i].judiciaryName+'</option>').appendTo('#sel');
                }
            })
        } else {
            $.post('/BaseInfos/selectorganization', { 'num': a }, function (o) {
                console.log(o);
                $('#sel').attr('name', 'insurer_id');
                for (var i = 0; i < o.length; i++) {
                    var hm = $('<option value=' + o[i].insurer_id + '>' + o[i].insurerName + '</option>').appendTo('#sel');
                }
            })
        }
    }
    $('#sel-job').change(function () {
        var val = $("#sel-job").find("option:selected").text();
        console.log(val);
        if (val.toString() == "管理员") {
            $('.sel-office').css('display','block');
        } else {
            $('.sel-office').css('display', 'none');
        }
    })
</script>

